import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-03-25
 * Time: 19:20
 */
class Solution {
    //暴力解法
    /*public static int[] twoSum(int[] nums, int target) {
        int[] temp = new int[2];
        for(int i = 0;i < nums.length - 1;i++){
            int cur = nums[i];
            temp[0] = i;
            for(int j = i + 1;j < nums.length;j++){
                int curNext = nums[j];
                temp[1] = j;
                if(cur + curNext == target){
                    return temp;
                }
            }
        }
        return null;
    }*/

    public static int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i< nums.length; i++) {
            if(map.containsKey(target - nums[i])) {
                return new int[] {map.get(target-nums[i]),i};
            }
            map.put(nums[i], i);
        }
        return null;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{3,2,4};
        int[] ret = twoSum(nums, 6);
        System.out.println(Arrays.toString(ret));

    }
}